const CONFIG = require('../../config.js');
// 文案匹配
let TEXTData = {};
Page({
	data: {
		navBgColor: '-webkit-gradient(linear, 0% 0%, 0% 100%,from(#1b64e5), to(#488dea))',
		loginInfo: null,
		dataList: [],
		pageNum: 1,
		pageSize: 6,
		textJsonData: []
	},

	// 快速申请方案管理信息列表
	getPlanData(){
		wx.request({
			url: CONFIG.host + "/system/quickApplyInfoController/getQuickApplyInfoListForAPP",
			data: {
				pageNum: this.data.pageNum,
				pageSize: this.data.pageSize
			},
			method: "GET",
			header: {
				'content-type': 'application/json',
				'Authorization': this.data.loginInfo.token
			},
			success: res => {
				if(res.data.code === 200){
					if(res.data.rows.length === 0){
						wx.showToast({
							title: '没有更多了',
							icon: 'none',
							duration: 2000
						});
						this.setData({
							isEmpty: true
						})
					}else{
						if(this.data.pageNum > 1){
							this.data.dataList = this.data.dataList.concat(res.data.rows);
						}else{
							this.data.dataList = res.data.rows;
						}
						this.setData({
							isEmpty: false,
							dataList: this.data.dataList
						})
					}
				}
			},fail: function (error) {
				console.log(error);
			}
		})
	},
	
	// 查看详情
	showDetailFn(e){
		let { id } = e.currentTarget.dataset;
		wx.navigateTo({
			url: '/pages/quickReport/quickReport?reportId=' + id,
		})
	},

	onLoad: function () {
		let showNum = wx.getStorageSync('showUser') === '0' ? '0' : '1';
		TEXTData = require('../../utils/text'+ showNum +'.js');
		let loginInfo = wx.getStorageSync('loginInfo') || '';
		if(loginInfo){
			this.setData({
				loginInfo : JSON.parse(loginInfo),
				textJsonData: TEXTData.textJson
			})
			this.getPlanData();
		}
	},
	
	/**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
	wx.showNavigationBarLoading();
	this.setData({
		pageNum: 1
	})
	this.getPlanData();
},
 /**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
	if(this.data.isEmpty) return;
	this.setData({
		pageNum: this.data.pageNum + 1
	})
	this.getPlanData();
},
})
